package com.slz3.business.module.drawManagement.draFreeLottery.steward;

import com.slz3.business.frame.redis.RK;
import com.slz3.business.frame.util.ConvertUtil;
import com.slz3.business.frame.util.RedisClient;
import com.slz3.business.module.drawManagement.draFreeLottery.vo.MemberDrawFreeInfo;

import java.util.Map;

/**
 * @author fengshiyou  on 2018/12/15 8:45 PM
 * 用户Redis信息工具类
 */
public class MemberRedisUtil {


    /**
     * 获取用户信息通过UUID
     * @param userUUID
     * @return
     */
    public static MemberDrawFreeInfo getUserUserInfoByUUID(String userUUID) {
        Map userInfo = RedisClient.redisTemplate.opsForHash().entries(generateUserInfoRedisKey(userUUID));
        return ConvertUtil.mapToObj(userInfo,MemberDrawFreeInfo.class);
    }

    /**
     * 获取用户信息通过 userID
     * @param userId
     * @return
     */
    public static MemberDrawFreeInfo getUserUserInfoByUserID(String userId) {
        return getUserUserInfoByUUID(getUserUUIDFromRedis(userId));
    }


    /**
     * 获取用户 自增ID 映射的 UUID
     * @param userId
     * @return
     */
    private static String getUserUUIDFromRedis(String userId){
        String redisUserKey =  RK.ID_MAP_UUID__API__$INCREMENT_ID$.replace("${incrementId}",userId);
        return  RedisClient.redisTemplate.opsForValue().get(redisUserKey).toString();
    }

    /**
     * 根据用户ID拼接用户Redis中查询key
     * @param userId 用户ID
     * @return
     */
    private static String generateUserInfoRedisKey(String userId){
        return RK.MEM_MEMBER__INFO__$UUID$.replace("${uuid}",userId);
    }


}
